package com.huidu.bitrade.util;


import com.alibaba.fastjson2.JSONObject;
import com.huidu.bitrade.constant.ResponseCode;
import lombok.Data;
import lombok.NoArgsConstructor;


@Data
@NoArgsConstructor
public class MessageResult<T> {

	private int code;
	private String message;
	private T data;

	private String totalPage;
	private String totalElement;

	public MessageResult(int code , String msg){
		this.code = code;
		this.message = msg;
	}
	public MessageResult(int code , String msg, T object){
		this.code = code;
		this.message = msg;
		this.data = object;
	}

	public static MessageResult success(){
		return new MessageResult(ResponseCode.SUCCESS,"SUCCESS");
	}
	public static MessageResult success(String msg){
		return new MessageResult(0,msg);
	}
	public static MessageResult success(String msg,Object data){
		return new MessageResult(0,msg,data);
	}

	public static MessageResult error(int code,String msg){
		return new MessageResult(code,msg);
	}
	public static MessageResult error(String msg){
		return new MessageResult(ResponseCode.FAIL,msg);
	}

	@Override
    public String toString(){
		return JSONObject.toJSONString(this);
		//return "{\"code\":"+code+",\"message\":\""+message+"\"}";
	}

	public static MessageResult getSuccessInstance(String message ,Object data){
		MessageResult result = success(message);
		result.setData(data);
		return result ;
	}
}
